home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-16 | 13.1 KB | 678 lines | [TEXT/CWIE] |
- #include <stdio.h>
- #include <stdlib.h>
- #include "InputSprocket.h"
- #include "SIOUX.h"
-
- enum
- {
- kNeedCount = 8
- };
-
- enum
- {
- kIconSuiteID_XThrust = 128,
- kIconSuiteID_YThrust,
- kIconSuiteID_ZThrust,
- kIconSuiteID_Look,
- kIconSuiteID_Fire,
- kIconSuiteID_Thrust,
- kIconSuiteID_Pause,
- kIconSuiteID_Start
- };
-
- Boolean gIsSuspended = false;
- ISpElementListReference gVirtualList = NULL;
- ISpElementReference gVirtualElements[kNeedCount] = {nil, nil, nil, nil, nil, nil, nil, nil};
-
-
-
- void ShowFourByte(OSType fourByte);
- void ShowFourByte(OSType fourByte)
- {
- putchar(((fourByte & 0xff000000) >> 24));
- putchar(((fourByte & 0x00ff0000) >> 16));
- putchar(((fourByte & 0x0000ff00) >> 8));
- putchar(((fourByte & 0x000000ff) >> 00));
- }
-
- void ShowStr63(const Str63 &theStr);
- void ShowStr63(const Str63 &theStr)
- {
- int i;
- int len = theStr[0];
- if (len > 63) { len = 63; }
-
- for(i=1; i <= len; i++)
- {
- putchar(theStr[i]);
- }
- }
-
-
- void PrintEvent(ISpElementEventPtr theEvent);
- void PrintEvent(ISpElementEventPtr theEvent)
- {
- float temp1 = ((float) theEvent->data)/((float) 0xFFFFFFFFU);
- float temp2 = 2.0*temp1-1.0;
-
- printf("when = [%lu] [%lu]\n", theEvent->when.hi, theEvent->when.lo);
- printf("data = 0x%lx (%f%) (%f%)\n", theEvent->data, temp1, temp2);
- printf("element = 0x%lx\n", theEvent->element);
- printf("refcon = %lx\n", theEvent->refCon);
-
- ISpElementInfo info;
- ISpElement_GetInfo(theEvent->element, &info);
-
- printf("label = ");
- ShowFourByte(info.theLabel);
- printf("\n");
-
- printf("kind = ");
- ShowFourByte(info.theKind);
- printf("\n");
-
- printf("string = ");
- ShowStr63(info.theString);
- printf("\n");
-
- printf("\n\n");
- }
-
-
- void PrintElementBlock(ISpElementReference *theElementReferences, UInt32 count);
- void PrintElementBlock(ISpElementReference *theElementReferences, UInt32 count)
- {
- printf("count = %d\n");
-
- int itr;
-
- for(itr = 0; itr < count; itr++)
- {
- printf(" element #%d\n",itr);
-
- ISpElementInfo info;
-
- ISpElement_GetInfo(theElementReferences[itr], &info);
-
- printf(" label = ");
- ShowFourByte(info.theLabel);
- printf("\n");
-
- printf(" kind = ");
- ShowFourByte(info.theKind);
- printf("\n");
-
- printf(" string = ");
- ShowStr63(info.theString);
- printf("\n\n");
- }
- }
-
- // if whichList is NULL then we use the global list
- static void GetAndPrintEvents(ISpElementListReference whichList)
- {
- OSErr err;
-
- if (whichList == NULL)
- {
- err = ISpGetGlobalElementList(&whichList);
- if (err)
- {
- printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
- return;
- }
- }
-
- err = ISpElementList_Flush(whichList);
- if (err)
- {
- printf("••• ISpElementList_Flush returned error (%ld)\n",err);
- return;
- }
-
- printf("getting events (press command to end)\n");
-
- while(1)
- {
- ISpElementEvent event;
- Boolean wasEvent;
-
- err = ISpElementList_GetNextEvent(whichList, sizeof(event), &event, &wasEvent);
- if (err)
- {
- printf("••• ISpElementList_GetNextEvent returned error (%ld)\n",err);
- return;
- }
-
- if (wasEvent)
- {
- PrintEvent(&event);
- }
-
- KeyMap theKeys;
- GetKeys(theKeys);
-
- if ((theKeys[1] & 0x8000))
- {
- break;
- }
-
- SIOUXHandleOneEvent(nil);
- }
- }
-
- static void TestListOfDevices(void)
- {
- ISpDeviceReference theDevices[100];
- UInt32 deviceCount;
- UInt32 deviceBufferSize = 100;
- UInt32 deviceItr;
- OSErr err;
-
- err = ISpDevices_Extract(deviceBufferSize, &deviceCount, theDevices);
- if (err)
- {
- printf("••• ISpDevices_Extract returned error (%ld)\n",err);
- return;
- }
-
- printf("# of devices = %ld\n",deviceCount);
- for(deviceItr = 0; deviceItr < deviceCount; deviceItr++)
- {
- printf(" device #%ld\n",deviceItr);
- ISpDeviceDefinition theDfn;
-
- err = ISpDevice_GetDefinition(theDevices[deviceItr], sizeof(ISpDeviceDefinition), &theDfn);
- if (err)
- {
- printf("••• ISpDevice_GetDefinition returned error (%ld)\n",err);
- return;
- }
-
- printf(" name = ");
- ShowStr63(theDfn.deviceName);
- printf("\n");
-
- printf(" class = ");
- ShowFourByte(theDfn.theDeviceClass);
- printf("\n");
-
- printf(" device identifier = ");
- ShowFourByte(theDfn.theDeviceIdentifier);
- printf("\n");
-
- printf(" permanent id = %ld\n",theDfn.permanentID);
-
- printf("\n\n");
- }
- }
-
-
- static void TestListOfElements(void)
- {
- ISpElementListReference globalList;
- OSErr err;
-
- err = ISpGetGlobalElementList(&globalList);
- if (err)
- {
- printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
- return;
- }
-
- ISpElementReference theElementReferences[200];
- UInt32 bufferSize = 200;
- UInt32 count;
-
- err = ISpElementList_Extract(globalList, bufferSize, &count, theElementReferences);
- if (err)
- {
- printf("••• ISpElementList_Extract returned error (%ld)\n",err);
- return;
- }
-
- PrintElementBlock(theElementReferences, count);
- }
-
-
- static void TestListOfButtons(void)
- {
- ISpElementListReference globalList;
- OSErr err;
-
- err = ISpGetGlobalElementList(&globalList);
- if (err)
- {
- printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
- return;
- }
-
- ISpElementReference theElementReferences[200];
- UInt32 bufferSize = 200;
- UInt32 count;
-
- err = ISpElementList_ExtractByKind(globalList, kISpElementKind_Button, bufferSize, &count, theElementReferences);
- if (err)
- {
- printf("••• ISpElementList_Extract returned error (%ld)\n",err);
- return;
- }
-
- PrintElementBlock(theElementReferences, count);
- }
-
-
- static void TestListOfDPads(void)
- {
- ISpElementListReference globalList;
- OSErr err;
-
- err = ISpGetGlobalElementList(&globalList);
- if (err)
- {
- printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
- return;
- }
-
- ISpElementReference theElementReferences[200];
- UInt32 bufferSize = 200;
- UInt32 count;
-
- err = ISpElementList_ExtractByKind(globalList, kISpElementKind_DPad, bufferSize, &count, theElementReferences);
- if (err)
- {
- printf("••• ISpElementList_Extract returned error (%ld)\n",err);
- return;
- }
-
- PrintElementBlock(theElementReferences, count);
- }
-
-
- static void TestListOfAxes(void)
- {
- ISpElementListReference globalList;
- OSErr err;
-
- err = ISpGetGlobalElementList(&globalList);
- if (err)
- {
- printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
- return;
- }
-
- ISpElementReference theElementReferences[200];
- UInt32 bufferSize = 200;
- UInt32 count;
-
- err = ISpElementList_ExtractByKind(globalList, kISpElementKind_Axis, bufferSize, &count, theElementReferences);
- if (err)
- {
- printf("••• ISpElementList_Extract returned error (%ld)\n",err);
- return;
- }
-
- PrintElementBlock(theElementReferences, count);
- }
-
-
- static void TestListOfXAxes(void)
- {
- ISpElementListReference globalList;
- OSErr err;
-
- err = ISpGetGlobalElementList(&globalList);
- if (err)
- {
- printf("••• ISpGetGlobalElementList returned error (%ld)\n",err);
- return;
- }
-
- ISpElementReference theElementReferences[200];
- UInt32 bufferSize = 200;
- UInt32 count;
-
- err = ISpElementList_ExtractByLabel(globalList, kISpElementLabel_XAxis, bufferSize, &count, theElementReferences);
- if (err)
- {
- printf("••• ISpElementList_Extract returned error (%ld)\n",err);
- return;
- }
-
- PrintElementBlock(theElementReferences, count);
- }
-
-
- static void TestSuspend(void)
- {
- OSErr err;
-
- err = ISpSuspend();
- if (err)
- {
- printf("••• ISpSuspend returned error (%ld)\n",err);
- return;
- }
-
- gIsSuspended = true;
- }
-
-
- static void TestResume(void)
- {
- OSErr err;
-
- err = ISpResume();
- if (err)
- {
- printf("••• ISpResume returned error (%ld)\n",err);
- return;
- }
-
- gIsSuspended = false;
- }
-
-
- static void TestCreateNeeds(void)
- {
- OSErr err;
-
- static ISpNeed myNeeds[kNeedCount] =
- {
- { "\pForward Thrust", kIconSuiteID_YThrust, kISpElementKind_Axis, kISpElementLabel_YAxis, 0 },
- { "\pSide Thrust", kIconSuiteID_XThrust, kISpElementKind_Axis, kISpElementLabel_XAxis, 0 },
- { "\pVertical Thrust", kIconSuiteID_ZThrust, kISpElementKind_Axis, kISpElementLabel_ZAxis, 0 },
- { "\pLook", kIconSuiteID_Look, kISpElementKind_Movement, kISpElementLabel_None, 0 },
- { "\pFire", kIconSuiteID_Fire, kISpElementKind_Button, kISpElementLabel_Fire, 0 },
- { "\pThrust", kIconSuiteID_Thrust, kISpElementKind_Button, kISpElementLabel_Fire, 0 },
- { "\pPause", kIconSuiteID_Pause, kISpElementKind_Button, kISpElementLabel_None, kISpNeedFlag_NoMultiConfig },
- { "\pStart/Stop", kIconSuiteID_Start, kISpElementKind_Button, kISpElementLabel_Start, kISpNeedFlag_NoMultiConfig }
- };
-
- if (gVirtualList == NULL)
- {
- printf("creating virtual elements\n");
-
- err = ISpElement_NewVirtualFromNeeds(kNeedCount, myNeeds, gVirtualElements, 0);
- if (err)
- {
- printf("••• ISpElement_NewVirtualFromNeeds returned error (%ld)\n",err);
- return;
- }
-
- err = ISpElementList_New(
- kNeedCount, // count
- gVirtualElements, // needs
- &gVirtualList, // virtual elements
- 0); // flags
- if (err)
- {
- printf("••• ISpElementList_New returned error (%ld)\n",err);
- return;
- }
-
- err = ISpInit(kNeedCount, // count
- myNeeds, // needs
- gVirtualElements, // virtual elements
- 'ISpT', // app
- 'foob', // sub
- 0, // flags
- 0, // set list resource id
- 0); // version
- if (err)
- {
- printf("••• ISpInit returned error (%ld)\n",err);
- return;
- }
- }
- }
-
-
- static void TestDestroyNeeds(void)
- {
- OSErr err;
-
- if (gVirtualList != NULL)
- {
- err = ISpElementList_Dispose(gVirtualList);
- gVirtualList = NULL;
- if (err)
- {
- printf("••• ISpElementList_Dispose returned error (%ld)\n",err);
- return;
- }
-
- err = ISpStop();
- if (err)
- {
- printf("••• ISpStop returned error (%ld)\n",err);
- return;
- }
-
- err = ISpElement_DisposeVirtual(kNeedCount, gVirtualElements);
- if (err)
- {
- printf("••• ISpElement_DisposeVirtual returned error (%ld)\n",err);
- return;
- }
- }
- }
-
-
- static void TestNeedsEvents(void)
- {
- TestCreateNeeds();
-
- if (gVirtualList != NULL)
- {
- GetAndPrintEvents(gVirtualList);
- }
- }
-
-
- static void TestConfiguration(void)
- {
- OSErr err;
-
- TestCreateNeeds();
-
- err = ISpConfigure(nil);
- if (err)
- {
- printf("••• ISpConfigure returned error (%ld)\n",err);
- return;
- }
- }
-
-
- static void TestEnableMouseAndKeyboard(Boolean enable)
- {
- enum {
- kDeviceList_COUNT = 10
- };
-
- UInt32 count;
- ISpDeviceReference deviceList[kDeviceList_COUNT];
-
- // NOTE: This is not the correct way to handle the list count thing. We
- // should actually call once with NULL for the device list, malloc a list of
- // that size, and call again.
-
- ISpDevices_ExtractByClass(
- kISpDeviceClass_Mouse,
- kDeviceList_COUNT,
- &count,
- deviceList);
-
- if (count > kDeviceList_COUNT)
- {
- count = kDeviceList_COUNT;
- }
-
- if (enable)
- {
- ISpDevices_Activate(
- count,
- deviceList);
- }
- else
- {
- ISpDevices_Deactivate(
- count,
- deviceList);
- }
-
- ISpDevices_ExtractByClass(
- kISpDeviceClass_Keyboard,
- kDeviceList_COUNT,
- &count,
- deviceList);
-
- if (count > kDeviceList_COUNT)
- {
- count = kDeviceList_COUNT;
- }
-
- if (enable)
- {
- ISpDevices_Activate(
- count,
- deviceList);
- }
- else
- {
- ISpDevices_Deactivate(
- count,
- deviceList);
- }
- }
-
-
- void main(void)
- {
- // tell SIOUX to shut up
- SIOUXSettings.autocloseonquit = true;
- SIOUXSettings.asktosaveonclose = false;
-
- printf("starting up...\n");
-
- Boolean theDoneFlag = false;
-
- while( !theDoneFlag )
- {
- UInt32 theChoice;
-
- printf("\n\n\n############################################################\n");
- if (gIsSuspended)
- {
- printf("• SUSPENDED •\n");
- }
-
- if (gVirtualList != NULL)
- {
- printf("• NEEDS ARE ACTIVE •\n");
- }
-
- printf("Please select from the following tests:\n");
- printf("\t 1. Exit\n");
- // printf("\t 2. Run all tests automatically\n");
- // printf("\t 3. Dump information needed for InputSprocket bug reports\n");
- printf("\t 4. List all devices\n");
- printf("\t 5. List all elements\n");
- printf("\t 6. List all buttons\n");
- printf("\t 7. List all directional pads\n");
- printf("\t 8. List all axes\n");
- printf("\t 9. List all X-axes\n");
- printf("\t10. Get events (stop when Control key pressed)\n");
- printf("\t11. Suspend\n");
- printf("\t12. Resume\n");
- printf("\t13. Create needs\n");
- printf("\t14. Destroy needs\n");
- printf("\t15. Get needs events\n");
- printf("\t16. Configuration dialog\n");
- printf("\t17. Enable mouse and keyboard\n");
- printf("\t18. Disable mouse and keyboard\n");
-
- printf("\n\tSelection: ");
-
- char theString[32];
- gets( theString );
- theChoice = atoi( theString );
-
- printf("\n\n");
-
- switch( theChoice )
- {
- case 1:
- theDoneFlag = true;
- break;
-
- case 4:
- TestListOfDevices();
- break;
-
- case 5:
- TestListOfElements();
- break;
-
- case 6:
- TestListOfButtons();
- break;
-
- case 7:
- TestListOfDPads();
- break;
-
- case 8:
- TestListOfAxes();
- break;
-
- case 9:
- TestListOfXAxes();
- break;
-
- case 10:
- GetAndPrintEvents(NULL);
- break;
-
- case 11:
- TestSuspend();
- break;
-
- case 12:
- TestResume();
- break;
-
- case 13:
- TestCreateNeeds();
- break;
-
- case 14:
- TestDestroyNeeds();
- break;
-
- case 15:
- TestNeedsEvents();
- break;
-
- case 16:
- TestConfiguration();
- break;
-
- case 17:
- TestEnableMouseAndKeyboard(true);
- break;
-
- case 18:
- TestEnableMouseAndKeyboard(false);
- break;
-
- default:
- printf("\nhuh?\n");
- break;
- }
-
- printf("\nThank you, please drive through.\n");
- }
- }
-